<?php
defined('SYSPATH') OR die('No direct access allowed.');
/**
 * header.php
 * @author ranuandra
 *
 * 15 Agu 2011 09:31:26
 *
 * 
 */

$models= array();
$types = array();
$merks = array();
$areas = array();

if(isset($post['model_id']) && $post['model_id']!='null')
{
	if(is_array($post['model_id']))
	{
		$dtmodels = $post['model_id'];
	}
	else 
	{
		$dtmodels = explode(',', $post['model_id']);
	}
}
if(isset($post['type_id']) && $post['type_id']!='null')
{
	if(is_array($post['type_id']))
	{
		$types = $post['type_id'];
	}
	else 
	{
		$types = split(',', $post['type_id']);
	}
}

if(isset($post['merk']) && $post['merk']!='null')
{
	if(is_array($post['merk']))
	{
		$merks = $post['merk'];
	}
	else 
	{
		$merks = split(',', $post['merk']);
	}
}

if(isset($post['area_id']) && $post['area_id']!='null' )
{
	if(is_array($post['area_id']))
	{
		$areas = $post['area_id'];
	}
	else 
	{

		$areas = split(',', $post['area_id']);
	}
}


$areas = ORM::factory('area')->order_by('area')->find_all()->as_array('id', 'area');
$models = ORM::factory('model')->order_by('model')->find_all()->as_array('id', 'model');

$typelist = ORM::factory('type');
if(count($merks) > 0)
{
	$typelist = $typelist->where_open();
	foreach ($merks as $merk)
	{
		$typelist = $typelist->or_where('merk_id', '=', $merk);
	}
	$typelist = $typelist->where_close();
}
$typelist = $typelist->find_all()->as_array('id', 'type');

$merklist = ORM::factory('merk')->order_by('merk')->find_all()->as_array('id', 'merk');

$arealist = array();
$arealist = $areas;
/*foreach($areas as $id=>$value)
{
	$arealist[$id] = $value;
}*/
//$arealist = array_merge(array(''=>'Silahkan Pilih Area'), $area);
$modellist = $models;
/*$modellist[0] = 'Silahkan Pilih Model';
foreach($models as $id=>$value)
{
	$modellist[$id] = $value;
}*/

//$merklist = array();
//$merklist = $merks;
/*foreach($merks as $id=>$value)
{
	$merklist[$id] = $value;
}*/


$jmlist = array();
$jmlist[0] = "Jumlah Kendaraan";
for($i=1; $i<10; $i++)
{
	$jmlist[$i] = $i;	
}

$thnini = date("Y");
$thnlalu = $thnini - 10;
$thnlist = array();
for($j=$thnini; $j>=$thnlalu; $j--)
{
	$thnlist[$j] = $j;
}




echo Form::open(URL::base().'report/'.$action, array('class' => 'searchdata', 'targetdata'=>'.tbldata'));
echo Form::hidden('submit', '1', array());
if(isset($post))
//echo Form::open(URL::base().'report/'.$action, array());
if(isset($hidden))
{
	//print_r($hidden);
	foreach($hidden as $key=>$value)
	{
		echo Form::hidden($key, $value, array());
	}
}

/*$typelist = array();
if(isset($post['merk']))
{
	if($post['merk']!="")
	{
		$types = ORM::factory('type')->where('merk_id', '=', $post['merk'])->find_all()->as_array('id', 'type');
		$typelist = $types;
		foreach($types as $id=>$value)
		{
			$typelist[$id] = $value;
		}
		
	}
}*/
?>
<table class="tableform">
	<tr>
		<?php
			if(isset($frmmodel))
			{		
		?>
			<td>
				<label class="formlabel">Model :</label>
				<?php
				echo Form::select('model_id[]', $modellist, $dtmodels, array('class'=>'element select medium','id' => 'selmodel', 'multiple'=>'multiple'));
				?>
			</td>
			
		<?php 
			}
			if(isset($frmmerk))
			{
		?>
			<td>
				<label class="formlabel">Merk :</label>
				<?php
				echo Form::select('merk[]', $merklist, $merks, array('class'=>'selopt_merk', 'id' => 'selmerk', 'target'=> URL::base().'report/typelist', 'multiple'=>'multiple'));
				?>
			</td>
		<?php
				
			}
		?>
		
			<td id="selopt_type">
			<?php 
			if(isset($post['merk']) or isset($frmtype))
			{
			?>
				
					<label class="formlabel">Type :</label>
					<?php 
					echo Form::select('type_id[]', $typelist, $types, array('class'=>'seltype', 'id'=>'seltype', 'multiple'=>'multiple'));
					?>
				
			<?php 			
			}
			?>
			</td>
		<td>			<?php 
				echo Form::submit('button', 'Search');
			?></td>
		<td>
			<a href="<?php echo URL::base()?>report/reportxls" class="xls"><img src="<?php echo URL::base()?>assets/images/excel.png"></a>
		</td>
	</tr>
	<tr>
		<?php 
			if(isset($frmarea))
			{
		?>
			<td>
				<label class="formlabel">Lokasi :</label>
				<?php 
				echo Form::select('area_id[]', $arealist, $areas, array('class'=>'element select medium', 'id'=>'selarea', 'multiple'=>'multiple'));
				?>
			</td>
		<?php 
			}
			if(isset($frmrange))
			{
		?>
			<td>
				<label class="formlabel">Range :</label>
				<?php 
				//echo Form::select('drthn', $thnlist, $post['drthn'], array('class'=>'element select medium'));
					$drthn = "";
					if(isset($post['drthn']))
					{
						$drthn = $post['drthn'];
					}
					echo Form::input('drthn', $drthn, array('id'=>'from'));
				?>
				-
				<?php 
				//echo Form::select('kethn', $thnlist, $post['kethn'], array('class'=>'element select medium'));
					$kethn = "";
					if(isset($post['kethn']))
					{
						$kethn = $post['kethn'];
					}					
					echo Form::input('kethn', $kethn, array('id'=>'to'));
				?>
			</td>

		<?php 
			}
			if(isset($frmjumlah))
			{		
		?>
			<td>	
				<label class="formlabel">Jumlah >= :</label>	
				<?php 
				$jumlah = "";
				if(isset($post['jumlah']))
				{
					$jumlah = $post['jumlah'];	
				}
				echo Form::select('jumlah', $jmlist, $jumlah, array('class'=>'element select medium', 'id'=>'sglsel'));
				
				?>				
			</td>
			<?php 
			}
			?>		
		<td>

		</td>
		<td>
		</td>
	</tr>
</table>
<?php 
Form::close();
?>